package com.le.edu.controller;

import com.le.edu.domain.entity.Comment;
import com.le.edu.domain.vo.CommentVO;
import com.le.edu.page.TableDataInfo;
import com.le.edu.resp.Result;
import com.le.edu.service.CommentService;
import com.le.edu.utils.JwtUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Le
 * @create 2024-04-27 16:37
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "评论接口")
@RequestMapping("/comment")
public class CommentController {
    private final CommentService commentService;

    @Operation(summary = "用户添加评论")
    @PostMapping("/v2/add")
    public Result<Void> UserAddComment(@RequestBody Comment comment,
                                       HttpServletRequest request) {
        Long userId = JwtUtils.getUserId(request);
        comment.setUserId(userId);
        commentService.save(comment);
        return Result.ok();
    }

    @Operation(summary = "更新评论列表")
    @GetMapping("/v2/tree")
    public TableDataInfo<CommentVO> updateCommentTreeList(Long courseId) {
        return TableDataInfo.build(commentService.updateCommentTreeList(courseId));
    }
}
